﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Kaidou.Model;
using Kaidou.Persister;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using Kaidou.Util;
using Kaidou.Bll;

public partial class seal_master_hall_search2 : System.Web.UI.Page
{
    private int pageSize = int.Parse(Resources.Resource.pagenumber);

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            table.Visible = false;
            none.Visible = false;
            string area = Resources.Resource.area;
            string[] areaArray = area.Split(',');
            for (int i = 0; i < areaArray.Length; i++)
            {
                ListItem item = new ListItem();
                item.Value = (i + 1) + "";
                item.Text = areaArray[i];
                HALL_PREF_CODE.Items.Insert(i + 1, item);
            }
        }
    }

    private void page(int no, bool back)
    {
        try
        {
            LoginModel loginModel = (LoginModel)Session["loginModel"];
            //カプセル化オブジェクト
            ReportSearchModel M = new ReportSearchModel();
            if (!back)
            {
                M.setHall_name(HALL_NAME.Text);
                M.setHall_pref_code(int.Parse(HALL_PREF_CODE.Text));
                M.setHall_city(HALL_CITY.Text);
                M.setHall_tel(HALL_TEL.Text);
                M.setUnion_code(loginModel.Unioncode);
                M.setUser_clss(loginModel.Userclss);
            }
            else
            {
                M = (ReportSearchModel)Session["searchReportModel"];

            }

            Session["searchReportModel"] = M;
            Session["pageNo"] = no;

            TRN_Report_H_Persister dao = new TRN_Report_H_Persister();
            if (no <= 0) no = 1;
            Pager pager = dao.searchHall(M, no, pageSize);
            
           // if (no > pager.Pages) no = pager.Pages;
          //  pager = dao.searchHall(M, no, pageSize);
            pageNo.Value = no.ToString();
            pages.Text = "全" + pager.Total + "件";
            ArrayList list = pager.List;

            if (list.Count == 0)
            {
                table.Visible = false;
                none.Visible = true;
            }
            else
            {
                none.Visible = false;
                table.Visible = true;

                //datatable.Rows.Clear();
                if (no == 1)
                {
                    prebutton.Visible = false;
                }
                else
                {
                    prebutton.Visible = true;
                    prebutton.Text = "≪ 前の" + pageSize + "件";

                }

                if (no == pager.Pages)
                {
                    nextbutton.Visible = false;

                }
                else
                {
                    nextbutton.Visible = true;
                    nextbutton.Text = " 次の" + pageSize + "件 ≫";
                }

                string area = Resources.Resource.area;
                string[] areaArray = area.Split(',');

                int totalms = 0;
                for (int i = 0; i < list.Count; i++)
                {
                    TrnReporth mu = (TrnReporth)list[i];
                    String hallname = mu.HallName;
                    String hallpref = "";
                    if (mu.HallPrefCode != 0)
                    {
                        hallpref = areaArray[mu.HallPrefCode-1];
                    }
                    String hall_city = "";
                    if (mu.HallCity != null)
                    {
                        hall_city = mu.HallCity;
                    }
                    String hall_ori_address = "";
                    if (mu.HallAddress != null)
                    {
                        hall_ori_address = mu.HallAddress;
                    }
                    String halladdress = hallpref + hall_city + hall_ori_address;
                    String halltel = "";
                    if (mu.HallTel != null)
                    {
                        halltel = mu.HallTel;
                    }
                    
                    TableRow row = new TableRow();

                    TableCell td = new TableCell();
                    td.BackColor = Color.White;
                    td.Height = 30;
                    td.HorizontalAlign = HorizontalAlign.Left;
                    td.Text = "<a href=\"javascript:fill('" + hallname + "'," + mu.HallPrefCode + ",'" + hall_city + "','" + hall_ori_address + "','" + halltel + "')\">" + hallname + "</a>";
                    row.Cells.Add(td);

                    td = new TableCell();
                    td.BackColor = Color.White;
                    td.Height = 30;
                    td.HorizontalAlign = HorizontalAlign.Left;
                    td.Text = halladdress;
                    row.Cells.Add(td);

                    td = new TableCell();
                    td.BackColor = Color.White;
                    td.Height = 30;
                    td.HorizontalAlign = HorizontalAlign.Left;
                    td.Text = halltel;
                    row.Cells.Add(td);

                    datatable.Rows.Add(row);
                }

            }
        }
        catch (Exception e)
        {

        }
    }

    protected void pre(object sender, EventArgs e)
    {
        Session.Remove("back");
        Session.Remove("searchReportModel");
        Session.Remove("pageNo");
        page(int.Parse(pageNo.Value) - 1, false);
    }

    protected void next(object sender, EventArgs e)
    {
        Session.Remove("back");
        Session.Remove("searchReportModel");
        Session.Remove("pageNo");
        page(int.Parse(pageNo.Value) + 1, false);
    }

    protected void search(object sender, EventArgs e)
    {
        Session.Remove("back");
        Session.Remove("searchReportModel");
        Session.Remove("pageNo");
        page(1, false);


    }
}
